package com.cjx.stars.utils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.cjx.stars.constant.RedisConstant;
import com.cjx.stars.pojo.table.User;
import com.cjx.stars.pojo.vo.UserVo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author cjx
 * @description Redis的一些辅助功能
 * @createDate 2024/3/4 13:27
 **/
@Component
public class RedisHelper {

    @Resource
    private  StringRedisTemplate stringRedisTemplate;

    public  boolean setLoginKey(User user, String token){
        UserVo userVo = BeanUtil.copyProperties(user, UserVo.class);
        String jsonUser = JSONUtil.toJsonStr(userVo);
        stringRedisTemplate.opsForValue().set(RedisConstant.USER_LOGIN_KEY + token, jsonUser, RedisConstant.USER_LOGIN_TTL, TimeUnit.MINUTES);
        return true;

    }
}
